<?php

namespace App\Http\Requests\Business;

use Illuminate\Foundation\Http\FormRequest;

class SalesmanRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'name' => 'required|max:10',
        ];
        switch (request()->method) {
            case 'POST':
                $rules['job_number'] = 'required|max:8|unique:salesman,job_number';
                break;
            case 'PUT':
                $rules['job_number'] = 'required|max:8|unique:salesman,job_number,' . request()->salesman;
                break;
            default:
                break;
        }

        return $rules;
    }

    public function messages()
    {
        return [
            'job_number.required' => '请输入业务员工号！',
            'job_number.max' => '业务员工号最大为8位！',
            'job_number.unique' => '业务员工号已经存在！',
            'name.required' => '请输入业务员姓名！',
            'name.max' => '业务员姓名长度最大为10个字符！',
        ];
    }
}
